<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/28
 * Time: 下午4:03
 */

namespace app\model;


class Order extends Base
{
    protected $pk = 'id';
    // 此处表名请务必设置为public
    public $table = 'order';

    /**
     * @purpose 关联附表
     * @return \think\model\relation\HasMany
     */
    public function attach () {
        return $this->hasMany('OrderAttach', 'order_id', 'id');
    }

    /**
     * @purpose 管理用户
     * @return \think\model\relation\HasOne
     */
    public function asMember () {
        return $this->hasOne('Member', 'uid', 'uid')
            ->bind('nickname,avatar');
    }
    /**
     * @purpose 通过条件获取数据条数
     * @param array $where
     * @return int
     */
    public function total(array $where = []):int
    {
        return (int) $this
            ->where($where)
            ->count();
    }
}